package com.mlxg;/**
 * @author zcy
 * @date 2025/5/14 15:13
 */

import com.baomidou.dynamic.datasource.DynamicRoutingDataSource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
import org.springframework.boot.autoconfigure.jdbc.DataSourceTransactionManagerAutoConfiguration;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.scheduling.annotation.EnableScheduling;

import javax.sql.DataSource;
import java.util.Map;

/**
 *   @author zcy
 *   @date 2025/5/14 15:13
 *   @description: 启动类
 */
@SpringBootApplication
@EnableScheduling
public class Application {
    public static void main(String[] args) {
        ConfigurableApplicationContext context = SpringApplication.run(Application.class, args);
        // 从 Spring 容器中获取 DataSource
        DataSource dataSource = context.getBean(DataSource.class);

        // 强制转换为 DynamicRoutingDataSource
        DynamicRoutingDataSource ds = (DynamicRoutingDataSource) dataSource;
        // 获取所有的数据源列表
        Map<String, DataSource> dataSources = ds.getDataSources(); // 这步获取数据源列表
        System.out.println("当前数据源列表: " + dataSources.keySet());

        // 获取默认数据源
        // 假设使用了默认配置，并且提供了相关的方法
//        String defaultDataSource = ds.determineDataSource(); // 根据您的实现调整方法
        System.out.println("默认数据源: " + ds.determineDataSource().getClass().getName());
    }
}
